package com.hdphone.zljutils.inter;

import com.hdphone.zljutils.impl.FileUtilImpl;

import java.io.File;
import java.io.FileFilter;
import java.util.List;

/**
 * @author sq
 * @date 2020/10/19
 * @describe
 */
public interface IFileUtil {

    /**
     * 获取文件的字节
     *
     * @param filePath
     * @return
     */
    byte[] getBytes(String filePath);

    /**
     * 获取文件夹大小
     *
     * @param file File实例
     * @return long 单位为M
     * @throws Exception
     */
    double getFolderSize(File file);

    /**
     * 根据文件路径获取文件
     *
     * @param filePath
     * @return
     */
    File getFileByPath(final String filePath);

    /**
     * 文件是否存在
     *
     * @param filePath
     * @return
     */
    boolean isFileExists(final String filePath);

    /**
     * 文件是否存在
     *
     * @param file
     * @return
     */
    boolean isFileExists(final File file);

    /**
     * 重命名文件
     *
     * @param filePath 文件路径
     * @param newName  新名称
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean rename(final String filePath, final String newName);

    /**
     * 重命名文件
     *
     * @param file    文件
     * @param newName 新名称
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean rename(final File file, final String newName);

    /**
     * 是否为文件夹
     *
     * @param dirPath
     * @return
     */
    boolean isDir(final String dirPath);

    /**
     * 是否为文件夹
     *
     * @param file
     * @return
     */
    boolean isDir(final File file);

    /**
     * 是否为文件
     *
     * @param filePath
     * @return
     */
    boolean isFile(final String filePath);

    /**
     * 是否为文件
     *
     * @param file
     * @return
     */
    boolean isFile(final File file);

    /**
     * 创建一个文件夹，如果不存在才创建
     *
     * @param dirPath
     * @return
     */
    boolean createOrExistsDir(final String dirPath);

    /**
     * 创建一个文件夹，如果不存在才创建
     *
     * @param file
     * @return
     */
    boolean createOrExistsDir(final File file);

    /**
     * 创建一个文件，如果不存在才创建
     *
     * @param filePath
     * @return
     */
    boolean createOrExistsFile(final String filePath);

    /**
     * 创建一个文件，如果不存在才创建
     *
     * @param file
     * @return
     */
    boolean createOrExistsFile(final File file);

    /**
     * 创建一个文件，如果存在就删除旧的
     *
     * @param filePath
     * @return
     */
    boolean createFileByDeleteOldFile(final String filePath);

    /**
     * 创建一个文件，如果存在就删除旧的
     *
     * @param file
     * @return
     */
    boolean createFileByDeleteOldFile(final File file);

    /**
     * 拷贝文件夹
     *
     * @param srcDirPath  源文件夹
     * @param destDirPath 目标文件夹
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean copyDir(final String srcDirPath,
                    final String destDirPath);

    /**
     * 拷贝文件夹
     *
     * @param srcDirPath  源文件夹
     * @param destDirPath 目标文件夹
     * @param listener    拷贝回调
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean copyDir(final String srcDirPath,
                    final String destDirPath,
                    final FileUtilImpl.OnReplacementListener listener);

    /**
     * 拷贝文件夹
     *
     * @param srcDir
     * @param destDir
     * @return
     */
    boolean copyDir(final File srcDir,
                    final File destDir);

    /**
     * 拷贝文件夹
     *
     * @param srcDir   源文件夹
     * @param destDir  目标文件夹
     * @param listener 拷贝回调
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean copyDir(final File srcDir,
                    final File destDir,
                    final FileUtilImpl.OnReplacementListener listener);

    /**
     * 拷贝文件
     *
     * @param srcFilePath
     * @param destFilePath
     * @return
     */
    boolean copyFile(final String srcFilePath,
                     final String destFilePath);

    /**
     * 拷贝文件
     *
     * @param srcFilePath
     * @param destFilePath
     * @param listener
     * @return
     */
    boolean copyFile(final String srcFilePath,
                     final String destFilePath,
                     final FileUtilImpl.OnReplacementListener listener);

    /**
     * 拷贝文件
     *
     * @param srcFile
     * @param destFile
     * @return
     */
    boolean copyFile(final File srcFile,
                     final File destFile);

    /**
     * 拷贝文件
     *
     * @param srcFile
     * @param destFile
     * @param listener
     * @return
     */
    boolean copyFile(final File srcFile,
                     final File destFile,
                     final FileUtilImpl.OnReplacementListener listener);


    /**
     * Move the directory.
     *
     * @param srcDirPath  The path of source directory.
     * @param destDirPath The path of destination directory.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean moveDir(final String srcDirPath,
                    final String destDirPath);

    /**
     * Move the directory.
     *
     * @param srcDirPath  The path of source directory.
     * @param destDirPath The path of destination directory.
     * @param listener    The replace listener.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean moveDir(final String srcDirPath,
                    final String destDirPath,
                    final FileUtilImpl.OnReplacementListener listener);

    /**
     * Move the directory.
     *
     * @param srcDir  The source directory.
     * @param destDir The destination directory.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean moveDir(final File srcDir,
                    final File destDir);

    /**
     * Move the directory.
     *
     * @param srcDir   The source directory.
     * @param destDir  The destination directory.
     * @param listener The replace listener.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean moveDir(final File srcDir,
                    final File destDir,
                    final FileUtilImpl.OnReplacementListener listener);

    /**
     * Move the file.
     *
     * @param srcFilePath  The path of source file.
     * @param destFilePath The path of destination file.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean moveFile(final String srcFilePath,
                     final String destFilePath);

    /**
     * Move the file.
     *
     * @param srcFilePath  The path of source file.
     * @param destFilePath The path of destination file.
     * @param listener     The replace listener.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean moveFile(final String srcFilePath,
                     final String destFilePath,
                     final FileUtilImpl.OnReplacementListener listener);

    /**
     * Move the file.
     *
     * @param srcFile  The source file.
     * @param destFile The destination file.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean moveFile(final File srcFile,
                     final File destFile);

    /**
     * Move the file.
     *
     * @param srcFile  The source file.
     * @param destFile The destination file.
     * @param listener The replace listener.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean moveFile(final File srcFile,
                     final File destFile,
                     final FileUtilImpl.OnReplacementListener listener);


    /**
     * Delete the directory.
     *
     * @param filePath The path of file.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean delete(final String filePath);

    /**
     * Delete the directory.
     *
     * @param file The file.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean delete(final File file);

    /**
     * Delete the directory.
     *
     * @param dirPath The path of directory.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean deleteDir(final String dirPath);

    /**
     * Delete the directory.
     *
     * @param dir The directory.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean deleteDir(final File dir);

    /**
     * Delete the file.
     *
     * @param srcFilePath The path of source file.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean deleteFile(final String srcFilePath);

    /**
     * Delete the file.
     *
     * @param file The file.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean deleteFile(final File file);

    /**
     * Delete the all in directory.
     *
     * @param dirPath The path of directory.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean deleteAllInDir(final String dirPath);

    /**
     * Delete the all in directory.
     *
     * @param dir The directory.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean deleteAllInDir(final File dir);

    /**
     * Delete all files in directory.
     *
     * @param dirPath The path of directory.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean deleteFilesInDir(final String dirPath);

    /**
     * Delete all files in directory.
     *
     * @param dir The directory.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean deleteFilesInDir(final File dir);

    /**
     * Delete all files that satisfy the filter in directory.
     *
     * @param dirPath The path of directory.
     * @param filter  The filter.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean deleteFilesInDirWithFilter(final String dirPath,
                                       final FileFilter filter);

    /**
     * Delete all files that satisfy the filter in directory.
     *
     * @param dir    The directory.
     * @param filter The filter.
     * @return {@code true}: success<br>{@code false}: fail
     */
    boolean deleteFilesInDirWithFilter(final File dir, final FileFilter filter);

    /**
     * Return the files in directory.
     * <p>Doesn't traverse subdirectories</p>
     *
     * @param dirPath The path of directory.
     * @return the files in directory
     */
    List<File> listFilesInDir(final String dirPath);

    /**
     * Return the files in directory.
     * <p>Doesn't traverse subdirectories</p>
     *
     * @param dir The directory.
     * @return the files in directory
     */
    List<File> listFilesInDir(final File dir);

    /**
     * Return the files in directory.
     *
     * @param dirPath     The path of directory.
     * @param isRecursive True to traverse subdirectories, false otherwise.
     * @return the files in directory
     */
    List<File> listFilesInDir(final String dirPath, final boolean isRecursive);

    /**
     * Return the files in directory.
     *
     * @param dir         The directory.
     * @param isRecursive True to traverse subdirectories, false otherwise.
     * @return the files in directory
     */
    List<File> listFilesInDir(final File dir, final boolean isRecursive);

    /**
     * Return the files that satisfy the filter in directory.
     * <p>Doesn't traverse subdirectories</p>
     *
     * @param dirPath The path of directory.
     * @param filter  The filter.
     * @return the files that satisfy the filter in directory
     */
    List<File> listFilesInDirWithFilter(final String dirPath,
                                        final FileFilter filter);

    /**
     * Return the files that satisfy the filter in directory.
     * <p>Doesn't traverse subdirectories</p>
     *
     * @param dir    The directory.
     * @param filter The filter.
     * @return the files that satisfy the filter in directory
     */
    List<File> listFilesInDirWithFilter(final File dir,
                                        final FileFilter filter);

    /**
     * Return the files that satisfy the filter in directory.
     *
     * @param dirPath     The path of directory.
     * @param filter      The filter.
     * @param isRecursive True to traverse subdirectories, false otherwise.
     * @return the files that satisfy the filter in directory
     */
    List<File> listFilesInDirWithFilter(final String dirPath,
                                        final FileFilter filter,
                                        final boolean isRecursive);

    /**
     * Return the files that satisfy the filter in directory.
     *
     * @param dir         The directory.
     * @param filter      The filter.
     * @param isRecursive True to traverse subdirectories, false otherwise.
     * @return the files that satisfy the filter in directory
     */
    List<File> listFilesInDirWithFilter(final File dir,
                                        final FileFilter filter,
                                        final boolean isRecursive);

    /**
     * Return the time that the file was last modified.
     *
     * @param filePath The path of file.
     * @return the time that the file was last modified
     */

    long getFileLastModified(final String filePath);

    /**
     * Return the time that the file was last modified.
     *
     * @param file The file.
     * @return the time that the file was last modified
     */
    long getFileLastModified(final File file);

    /**
     * Return the charset of file simply.
     *
     * @param filePath The path of file.
     * @return the charset of file simply
     */
    String getFileCharsetSimple(final String filePath);

    /**
     * Return the charset of file simply.
     *
     * @param file The file.
     * @return the charset of file simply
     */
    String getFileCharsetSimple(final File file);

    /**
     * Return the number of lines of file.
     *
     * @param filePath The path of file.
     * @return the number of lines of file
     */
    int getFileLines(final String filePath);

    /**
     * Return the number of lines of file.
     *
     * @param file The file.
     * @return the number of lines of file
     */
    int getFileLines(final File file);

    /**
     * Return the size of directory.
     *
     * @param dirPath The path of directory.
     * @return the size of directory
     */
    String getDirSize(final String dirPath);

    /**
     * Return the size of directory.
     *
     * @param dir The directory.
     * @return the size of directory
     */
    String getDirSize(final File dir);

    /**
     * Return the length of file.
     *
     * @param filePath The path of file.
     * @return the length of file
     */
    String getFileSize(final String filePath);

    /**
     * Return the length of file.
     *
     * @param file The file.
     * @return the length of file
     */
    String getFileSize(final File file);

    /**
     * Return the length of directory.
     *
     * @param dirPath The path of directory.
     * @return the length of directory
     */
    long getDirLength(final String dirPath);

    /**
     * Return the length of directory.
     *
     * @param dir The directory.
     * @return the length of directory
     */
    long getDirLength(final File dir);

    /**
     * Return the length of file.
     *
     * @param filePath The path of file.
     * @return the length of file
     */
    long getFileLength(final String filePath);

    /**
     * Return the length of file.
     *
     * @param file The file.
     * @return the length of file
     */
    long getFileLength(final File file);

    /**
     * Return the MD5 of file.
     *
     * @param filePath The path of file.
     * @return the md5 of file
     */
    String getFileMD5ToString(final String filePath);

    /**
     * Return the MD5 of file.
     *
     * @param file The file.
     * @return the md5 of file
     */
    String getFileMD5ToString(final File file);

    /**
     * Return the MD5 of file.
     *
     * @param filePath The path of file.
     * @return the md5 of file
     */
    byte[] getFileMD5(final String filePath);

    /**
     * Return the MD5 of file.
     *
     * @param file The file.
     * @return the md5 of file
     */
    byte[] getFileMD5(final File file);

    /**
     * Return the file's path of directory.
     *
     * @param file The file.
     * @return the file's path of directory
     */
    String getDirName(final File file);

    /**
     * Return the file's path of directory.
     *
     * @param filePath The path of file.
     * @return the file's path of directory
     */
    String getDirName(final String filePath);

    /**
     * Return the name of file.
     *
     * @param file The file.
     * @return the name of file
     */
    String getFileName(final File file);

    /**
     * Return the name of file.
     *
     * @param filePath The path of file.
     * @return the name of file
     */
    String getFileName(final String filePath);

    /**
     * Return the name of file without extension.
     *
     * @param file The file.
     * @return the name of file without extension
     */
    String getFileNameNoExtension(final File file);

    /**
     * Return the name of file without extension.
     *
     * @param filePath The path of file.
     * @return the name of file without extension
     */
    String getFileNameNoExtension(final String filePath);

    /**
     * Return the extension of file.
     *
     * @param file The file.
     * @return the extension of file
     */
    String getFileExtension(final File file);

    /**
     * Return the extension of file.
     *
     * @param filePath The path of file.
     * @return the extension of file
     */
    String getFileExtension(final String filePath);
}
